{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "d1847b20",
   "metadata": {},
   "outputs": [],
   "source": [
    "##########################数组的拼接#######################33"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "b6f7dff9",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[1 2]\n",
      " [3 4]]\n",
      "******************************\n",
      "[[5 6]\n",
      " [7 8]]\n"
     ]
    }
   ],
   "source": [
    "import numpy as np\n",
    "# 1. 根据轴连接的数组序列\n",
    "a = np.array([[1,2],[3,4]])\n",
    "b = np.array([[5,6],[7,8]])\n",
    "\n",
    "print(a)\n",
    "print('*'*30)\n",
    "print(b)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "338d6338",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "沿轴 0 连接两个数组：\n",
      "[[1 2]\n",
      " [3 4]\n",
      " [5 6]\n",
      " [7 8]]\n",
      "沿轴 1 连接两个数组：\n",
      "[[1 2 5 6]\n",
      " [3 4 7 8]]\n"
     ]
    }
   ],
   "source": [
    "# 要求 a,b 两个数组的维度相同\n",
    "print ('沿轴 0 连接两个数组：')\n",
    "print (np.concatenate((a,b),axis= 0))\n",
    "\n",
    "print ('沿轴 1 连接两个数组：')\n",
    "print (np.concatenate((a,b),axis = 1))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "10e37771",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "沿轴 0 连接两个数组：\n",
      "[[[1 2]\n",
      "  [3 4]]\n",
      "\n",
      " [[5 6]\n",
      "  [7 8]]]\n",
      "沿轴 1 连接两个数组：\n",
      "[[[1 2]\n",
      "  [5 6]]\n",
      "\n",
      " [[3 4]\n",
      "  [7 8]]]\n"
     ]
    }
   ],
   "source": [
    "# 2. 根据轴进行堆叠\n",
    "print ('沿轴 0 连接两个数组：')\n",
    "print (np.stack((a,b),axis= 0))\n",
    "\n",
    "print ('沿轴 1 连接两个数组：')\n",
    "print (np.stack((a,b),axis = 1))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "6647d7c6",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[ 0  1  2  3  4  5]\n",
      " [ 6  7  8  9 10 11]\n",
      " [12 13 14 15 16 17]\n",
      " [18 19 20 21 22 23]]\n"
     ]
    }
   ],
   "source": [
    "# 3. 矩阵垂直拼接\n",
    "v1 = [[0,1,2,3,4,5],[6,7,8,9,10,11]]\n",
    "v2 = [[12,13,14,15,16,17],[18,19,20,21,22,23]]\n",
    "result = np.vstack((v1,v2))\n",
    "print(result)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "b9a7c0f6",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[ 0  1  2  3  4  5 12 13 14 15 16 17]\n",
      " [ 6  7  8  9 10 11 18 19 20 21 22 23]]\n"
     ]
    }
   ],
   "source": [
    "# 4. 矩阵水平拼接\n",
    "v1 = [[0,1,2,3,4,5],[6,7,8,9,10,11]]\n",
    "v2 = [[12,13,14,15,16,17],[18,19,20,21,22,23]]\n",
    "result = np.hstack((v1,v2))\n",
    "print(result)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "bd41067b",
   "metadata": {},
   "outputs": [],
   "source": [
    "############################数组的分割##################################"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "df731f1e",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[0 1 2]\n",
      " [3 4 5]\n",
      " [6 7 8]]\n",
      "将数组分为三个大小相等的子数组：\n",
      "[array([[0, 1, 2]]), array([[3, 4, 5]]), array([[6, 7, 8]])]\n"
     ]
    }
   ],
   "source": [
    "import numpy as np\n",
    "arr = np.arange(9).reshape(3,3)\n",
    "print(arr)\n",
    "print ('将数组分为三个大小相等的子数组：')\n",
    "b = np.split(arr,3)\n",
    "print (b)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "177714de",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "原 array：\n",
      "[[4. 1. 2. 4. 6. 7.]\n",
      " [3. 5. 0. 0. 8. 9.]]\n"
     ]
    }
   ],
   "source": [
    "harr = np.floor(10*np.random.random((2, 6)))\n",
    "print ('原 array：')\n",
    "print(harr)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "034c7e2f",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "拆分后：\n",
      "[array([[4., 1.],\n",
      "       [3., 5.]]), array([[2., 4.],\n",
      "       [0., 0.]]), array([[6., 7.],\n",
      "       [8., 9.]])]\n"
     ]
    }
   ],
   "source": [
    "print ('拆分后：')\n",
    "print(np.hsplit(harr, 3))     #.hsplit 函数用于水平分割数组，通过指定要返回的相同形状的数组数量来拆分原数zu"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "75a4803f",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "第一个数组：\n",
      "[[ 0  1  2  3]\n",
      " [ 4  5  6  7]\n",
      " [ 8  9 10 11]\n",
      " [12 13 14 15]]\n",
      "\n",
      "\n"
     ]
    }
   ],
   "source": [
    "# 3.numpy.vsplit 沿着垂直轴分割\n",
    "a = np.arange(16).reshape(4,4)\n",
    "print ('第一个数组：')\n",
    "print (a)\n",
    "print ('\\n')\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "60ab4c8d",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "竖直分割：\n",
      "[array([[0, 1, 2, 3],\n",
      "       [4, 5, 6, 7]]), array([[ 8,  9, 10, 11],\n",
      "       [12, 13, 14, 15]])]\n"
     ]
    }
   ],
   "source": [
    "print ('竖直分割：')\n",
    "b = np.vsplit(a,2)\n",
    "print (b)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "id": "b3eb8c79",
   "metadata": {},
   "outputs": [],
   "source": [
    "###############################3数组中nan和inf###################################\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "id": "0d476c9d",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "nan <class 'float'>\n",
      "inf <class 'float'>\n"
     ]
    }
   ],
   "source": [
    "import numpy as np\n",
    "# 创建一个 nan 和 inf #\n",
    "a = np.nan\n",
    "b = np.inf\n",
    "print(a,type(a))\n",
    "print(b,type(b))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "id": "2d81d5ed",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[ 0.,  1.,  2.,  3.,  4.,  5.],\n",
       "       [ 6.,  7.,  8.,  9., 10., 11.],\n",
       "       [12., 13., 14., 15., 16., 17.],\n",
       "       [18., 19., 20., 21., 22., 23.]])"
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# --判断数组中为 nan 的个数\n",
    "t = np.arange(24,dtype=float).reshape(4,6)\n",
    "t"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "id": "6a40d076",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[ 0.,  1.,  2.,  3.,  4.,  5.],\n",
       "       [ 6.,  7.,  8.,  9., 10., 11.],\n",
       "       [12., 13., 14., 15., 16., 17.],\n",
       "       [18., 19., 20., 21., nan, 23.]])"
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 将三行四列的数改成 nan\n",
    "t[3,4] = np.nan\n",
    "t"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "id": "b7344d8d",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "23\n"
     ]
    }
   ],
   "source": [
    "# 可以使用 np.count_nonzero() 来判断非零的个数\n",
    "print(np.count_nonzero(t))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "id": "f8b34f2d",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 26,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.nan !=np.nan"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "id": "8753e546",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1\n"
     ]
    }
   ],
   "source": [
    "print(np.count_nonzero(True))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "id": "66fbf5aa",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1\n"
     ]
    }
   ],
   "source": [
    "#结合两者来查看t中nan的个数\n",
    "print(np.count_nonzero(t != t))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "id": "f3365cc9",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[ 0.  1.  2.  3.  4.  5.]\n",
      " [ 6.  7.  8.  9. 10. 11.]\n",
      " [12. 13. 14. 15. 16. 17.]\n",
      " [18. 19. 20. 21.  0. 23.]]\n"
     ]
    }
   ],
   "source": [
    "# 将 nan 替换为 0\n",
    "t[np.isnan(t)] = 0\n",
    "print(t)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "id": "fbb7d003",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[ 0.  1.  2.  3.  4.  5.]\n",
      " [ 6.  7.  8. nan nan nan]\n",
      " [12. 13. 14. 15. 16. 17.]\n",
      " [18. 19. 20. 21. 22. 23.]]\n"
     ]
    }
   ],
   "source": [
    "# ----------练习： 处理数组中 nan\n",
    "t = np.arange(24).reshape(4,6).astype('float')\n",
    "#\n",
    "# 将数组中的一部分替换 nan\n",
    "t[1,3:] = np.nan\n",
    "print(t)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "id": "fa05b6d9",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "6"
      ]
     },
     "execution_count": 37,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "t.shape[1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "id": "d9ea87f5",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[ 0.,  1.,  2.,  3.,  4.,  5.],\n",
       "       [ 6.,  7.,  8., 13., 14., 15.],\n",
       "       [12., 13., 14., 15., 16., 17.],\n",
       "       [18., 19., 20., 21., 22., 23.]])"
      ]
     },
     "execution_count": 39,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "for i in range(t.shape[1]):\n",
    "    temp_clo = t[:,i]\n",
    "    nan_num=np.count_nonzero(temp_clo != temp_clo)\n",
    "    if nan_num != 0:\n",
    "        #将不是nan的数值拿出来\n",
    "        temp = temp_clo[temp_clo == temp_clo]\n",
    "        #替换上平均值\n",
    "        temp_clo[np.isnan(temp_clo)] = np.mean(temp)\n",
    "        \n",
    "t"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "id": "e5da675e",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[ 1.  2.  3. nan  3.  4.  5.]\n",
      "[False False False  True False False False]\n"
     ]
    }
   ],
   "source": [
    "test = np.array([1,2,3,np.nan,3,4,5])\n",
    "print(test)\n",
    "print(np.isnan(test))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "949c861e",
   "metadata": {},
   "outputs": [],
   "source": [
    "############################################313 二维数组的转置，轴滚动####################################3"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 45,
   "id": "0b97aed8",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "原数组：\n",
      "[[ 0  1  2  3]\n",
      " [ 4  5  6  7]\n",
      " [ 8  9 10 11]]\n"
     ]
    }
   ],
   "source": [
    "import numpy as np\n",
    "a = np.arange(12).reshape(3,4)\n",
    "print ('原数组：')\n",
    "print (a )"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 46,
   "id": "8bb5391d",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "对换数组：\n",
      "[[ 0  4  8]\n",
      " [ 1  5  9]\n",
      " [ 2  6 10]\n",
      " [ 3  7 11]]\n"
     ]
    }
   ],
   "source": [
    "print ('对换数组：')\n",
    "print (np.transpose(a))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 48,
   "id": "2a19e0ca",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[ 0,  1,  2,  3],\n",
       "       [ 4,  5,  6,  7],\n",
       "       [ 8,  9, 10, 11]])"
      ]
     },
     "execution_count": 48,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 与 transpose 一致\n",
    "a = np.arange(12).reshape(3,4)\n",
    "a"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 49,
   "id": "9072c7dd",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "转置数组：\n",
      "[[ 0  4  8]\n",
      " [ 1  5  9]\n",
      " [ 2  6 10]\n",
      " [ 3  7 11]]\n"
     ]
    }
   ],
   "source": [
    "print ('转置数组：')\n",
    "print (a.T)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 51,
   "id": "92f1e66f",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[ 0,  1,  2,  3,  4,  5],\n",
       "       [ 6,  7,  8,  9, 10, 11],\n",
       "       [12, 13, 14, 15, 16, 17],\n",
       "       [18, 19, 20, 21, 22, 23]])"
      ]
     },
     "execution_count": 51,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 函数用于交换数组的两个轴\n",
    "t1 = np.arange(24).reshape(4,6)\n",
    "t1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 66,
   "id": "e9ebc2a6",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "调用 swapaxes 函数后的数组：\n",
      "[[ 0  6 12 18]\n",
      " [ 1  7 13 19]\n",
      " [ 2  8 14 20]\n",
      " [ 3  9 15 21]\n",
      " [ 4 10 16 22]\n",
      " [ 5 11 17 23]]\n"
     ]
    }
   ],
   "source": [
    "re = t1.swapaxes(1,0)\n",
    "print ('调用 swapaxes 函数后的数组：')\n",
    "print (re)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 65,
   "id": "fecaec74",
   "metadata": {},
   "outputs": [
    {
     "ename": "AxisError",
     "evalue": "axis 2 is out of bounds for array of dimension 1",
     "output_type": "error",
     "traceback": [
      "\u001B[1;31m---------------------------------------------------------------------------\u001B[0m",
      "\u001B[1;31mAxisError\u001B[0m                                 Traceback (most recent call last)",
      "Cell \u001B[1;32mIn[65], line 2\u001B[0m\n\u001B[0;32m      1\u001B[0m t \u001B[38;5;241m=\u001B[39m np\u001B[38;5;241m.\u001B[39marange(\u001B[38;5;241m12\u001B[39m)\u001B[38;5;241m.\u001B[39mreshape(\u001B[38;5;241m12\u001B[39m,)\n\u001B[1;32m----> 2\u001B[0m t\u001B[38;5;241m=\u001B[39m\u001B[43mnp\u001B[49m\u001B[38;5;241;43m.\u001B[39;49m\u001B[43mrollaxis\u001B[49m\u001B[43m(\u001B[49m\u001B[43mt\u001B[49m\u001B[43m,\u001B[49m\u001B[38;5;241;43m2\u001B[39;49m\u001B[43m,\u001B[49m\u001B[38;5;241;43m0\u001B[39;49m\u001B[43m)\u001B[49m\n\u001B[0;32m      3\u001B[0m \u001B[38;5;28mprint\u001B[39m(t\u001B[38;5;241m.\u001B[39mshape)\n",
      "File \u001B[1;32m<__array_function__ internals>:200\u001B[0m, in \u001B[0;36mrollaxis\u001B[1;34m(*args, **kwargs)\u001B[0m\n",
      "File \u001B[1;32m~\\AppData\\Local\\Programs\\Python\\Python39\\lib\\site-packages\\numpy\\core\\numeric.py:1331\u001B[0m, in \u001B[0;36mrollaxis\u001B[1;34m(a, axis, start)\u001B[0m\n\u001B[0;32m   1260\u001B[0m \u001B[38;5;250m\u001B[39m\u001B[38;5;124;03m\"\"\"\u001B[39;00m\n\u001B[0;32m   1261\u001B[0m \u001B[38;5;124;03mRoll the specified axis backwards, until it lies in a given position.\u001B[39;00m\n\u001B[0;32m   1262\u001B[0m \n\u001B[1;32m   (...)\u001B[0m\n\u001B[0;32m   1328\u001B[0m \n\u001B[0;32m   1329\u001B[0m \u001B[38;5;124;03m\"\"\"\u001B[39;00m\n\u001B[0;32m   1330\u001B[0m n \u001B[38;5;241m=\u001B[39m a\u001B[38;5;241m.\u001B[39mndim\n\u001B[1;32m-> 1331\u001B[0m axis \u001B[38;5;241m=\u001B[39m \u001B[43mnormalize_axis_index\u001B[49m\u001B[43m(\u001B[49m\u001B[43maxis\u001B[49m\u001B[43m,\u001B[49m\u001B[43m \u001B[49m\u001B[43mn\u001B[49m\u001B[43m)\u001B[49m\n\u001B[0;32m   1332\u001B[0m \u001B[38;5;28;01mif\u001B[39;00m start \u001B[38;5;241m<\u001B[39m \u001B[38;5;241m0\u001B[39m:\n\u001B[0;32m   1333\u001B[0m     start \u001B[38;5;241m+\u001B[39m\u001B[38;5;241m=\u001B[39m n\n",
      "\u001B[1;31mAxisError\u001B[0m: axis 2 is out of bounds for array of dimension 1"
     ]
    }
   ],
   "source": [
    "t = np.arange(12).reshape(12,)\n",
    "t=np.rollaxis(t,2,0)\n",
    "print(t.shape)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 67,
   "id": "0832a7d3",
   "metadata": {},
   "outputs": [
    {
     "ename": "AxisError",
     "evalue": "axis 2 is out of bounds for array of dimension 1",
     "output_type": "error",
     "traceback": [
      "\u001B[1;31m---------------------------------------------------------------------------\u001B[0m",
      "\u001B[1;31mAxisError\u001B[0m                                 Traceback (most recent call last)",
      "Cell \u001B[1;32mIn[67], line 2\u001B[0m\n\u001B[0;32m      1\u001B[0m t \u001B[38;5;241m=\u001B[39m np\u001B[38;5;241m.\u001B[39marange(\u001B[38;5;241m12\u001B[39m)\u001B[38;5;241m.\u001B[39mreshape(\u001B[38;5;241m12\u001B[39m,)\n\u001B[1;32m----> 2\u001B[0m t\u001B[38;5;241m=\u001B[39m\u001B[43mnp\u001B[49m\u001B[38;5;241;43m.\u001B[39;49m\u001B[43mrollaxis\u001B[49m\u001B[43m(\u001B[49m\u001B[43mt\u001B[49m\u001B[43m,\u001B[49m\u001B[38;5;241;43m2\u001B[39;49m\u001B[43m,\u001B[49m\u001B[38;5;241;43m0\u001B[39;49m\u001B[43m)\u001B[49m\n\u001B[0;32m      3\u001B[0m \u001B[38;5;28mprint\u001B[39m(t\u001B[38;5;241m.\u001B[39mshape)\n",
      "File \u001B[1;32m<__array_function__ internals>:200\u001B[0m, in \u001B[0;36mrollaxis\u001B[1;34m(*args, **kwargs)\u001B[0m\n",
      "File \u001B[1;32m~\\AppData\\Local\\Programs\\Python\\Python39\\lib\\site-packages\\numpy\\core\\numeric.py:1331\u001B[0m, in \u001B[0;36mrollaxis\u001B[1;34m(a, axis, start)\u001B[0m\n\u001B[0;32m   1260\u001B[0m \u001B[38;5;250m\u001B[39m\u001B[38;5;124;03m\"\"\"\u001B[39;00m\n\u001B[0;32m   1261\u001B[0m \u001B[38;5;124;03mRoll the specified axis backwards, until it lies in a given position.\u001B[39;00m\n\u001B[0;32m   1262\u001B[0m \n\u001B[1;32m   (...)\u001B[0m\n\u001B[0;32m   1328\u001B[0m \n\u001B[0;32m   1329\u001B[0m \u001B[38;5;124;03m\"\"\"\u001B[39;00m\n\u001B[0;32m   1330\u001B[0m n \u001B[38;5;241m=\u001B[39m a\u001B[38;5;241m.\u001B[39mndim\n\u001B[1;32m-> 1331\u001B[0m axis \u001B[38;5;241m=\u001B[39m \u001B[43mnormalize_axis_index\u001B[49m\u001B[43m(\u001B[49m\u001B[43maxis\u001B[49m\u001B[43m,\u001B[49m\u001B[43m \u001B[49m\u001B[43mn\u001B[49m\u001B[43m)\u001B[49m\n\u001B[0;32m   1332\u001B[0m \u001B[38;5;28;01mif\u001B[39;00m start \u001B[38;5;241m<\u001B[39m \u001B[38;5;241m0\u001B[39m:\n\u001B[0;32m   1333\u001B[0m     start \u001B[38;5;241m+\u001B[39m\u001B[38;5;241m=\u001B[39m n\n",
      "\u001B[1;31mAxisError\u001B[0m: axis 2 is out of bounds for array of dimension 1"
     ]
    }
   ],
   "source": [
    "t = np.arange(12).reshape(12,)\n",
    "t=np.rollaxis(t,2,0)\n",
    "print(t.shape)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.7"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}